/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.Entity;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author BachLe
 */
@Stateless
public class UsersFacade extends AbstractFacade<Users> {
    @PersistenceContext(unitName = "Alluring_Decors-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsersFacade() {
        super(Users.class);
    }

    public Users getUserByUsername(String username, String pass){
        return (Users)em.createQuery("SELECT u FROM Users u WHERE u.userName = :userName and u.passowrd = :passowrd")
                .setParameter("userName", username).setParameter("passowrd", pass).getSingleResult();
    }

    public Users insertUser(Users user){
        return (Users)em.createQuery(
                "Insert into Users u values(u.username= :userName and u.passowrd= :password and u.fullName=:fullname"
                + "and u.address= :address and u.email= :email and u.phone= :phone)").setParameter("userName", user.getUserName())
                .setParameter("passowrd", user.getPassowrd()).setParameter("fullName", user.getFullName()).setParameter("address", user.getAddress())
                .setParameter("email", user.getEmail()).setParameter("phone", user.getPhone());
    }
}
